// views/index/shop/visahandle/index.js
var BASE_URL = getApp().globalData.BASE_URL

Page({

  /**
   * 页面的初始数据
   */
  data: {
    dingjichecked: false,
    xuelichecked: false,
    jianlichecked: false,
    quantaochecked: false,
    price: 799
  },
  ondingji(event) {
    this.setData({
      dingjichecked: event.detail,
    });
    if (event.detail) {
      if (this.data.quantaochecked) {
        this.setData({
          price: this.data.price - 600 + 499,
          quantaochecked: false,
        })
      } else {
        this.setData({
          price: this.data.price + 499
        })
      }
    } else {
      this.setData({
        price: this.data.price - 499
      })
    }
  },
  onxueli(event) {
    this.setData({
      xuelichecked: event.detail,
    });
    if (event.detail) {
      if (this.data.quantaochecked) {
        this.setData({
          price: this.data.price - 600 + 200,
          quantaochecked: false,
        })
      } else {
        this.setData({
          price: this.data.price + 200
        })
      }
    } else {
      this.setData({
        price: this.data.price - 200
      })
    }
  },
  onjianli(event) {
    this.setData({
      jianlichecked: event.detail,
    });
    if (event.detail) {
      if (this.data.quantaochecked) {
        this.setData({
          price: this.data.price - 600 + 159,
          quantaochecked: false,
        })
      } else {
        this.setData({
          price: this.data.price + 159
        })
      }
    } else {
      this.setData({
        price: this.data.price - 159
      })
    }
  },
  onquantao(event) {
    this.setData({
      quantaochecked: event.detail,
    });
    if (event.detail) {
      this.setData({
        price: 1399,
        xuelichecked: false,
        jianlichecked: false,
        dingjichecked: false,
      })
    } else {
      this.setData({
        price: 799
      })
    }
  },




  //立即办理留学签证
  placeliuxueorder: function () {
    var userinfo = wx.getStorageSync("USER")
    var _this = this
    if (_this.data.quantaochecked) {
      wx.request({
        url: `${BASE_URL}/visa/liuxueZhuan`,
        method: "POST",
        data: {
          type: 'xiaochengxv',

          uid: userinfo.id,
          all_serve: 600
        },
        header: {
          'Content-Type': 'application/json' //GET方式是这个
        },
        success(res) {
          console.log(res)
          wx.navigateTo({
            url: `./liuxue_visa/index?id=${res.data.id}&price=${_this.data.price}`,
          })
        }
      })
    } else if (_this.data.dingjichecked || _this.data.xuelichecked || _this.data.jianlichecked) {
      wx.request({
        url: `${BASE_URL}/visa/liuxueZhuan`,
        method: "POST",
        data: {
          type: 'xiaochengxv',
          uid: userinfo.id,
          serve: [_this.data.dingjichecked ? 499 : '', _this.data.xuelichecked ? 200 : '', _this.data.jianlichecked ? 159 : '']
        },
        header: {
          'Content-Type': 'application/json' //GET方式是这个
        },
        success(res) {
          console.log(res)
          wx.navigateTo({
            url: `./liuxue_visa/index?price=${_this.data.price}`,
          })
        }
      })
    } else {
      wx.request({
        url: `${BASE_URL}/visa/liuxueZhuan`,
        method: "POST",
        data: {
          type: 'xiaochengxv',
          uid: userinfo.id,
        },
        header: {
          'Content-Type': 'application/json' //GET方式是这个
        },
        success(res) {
          console.log(res)
          wx.navigateTo({
            url: `./liuxue_visa/index?price=${_this.data.price}`,
          })
        }
      })
    }
  },

  placelvxueorder: function (e) {
    var userinfo = wx.getStorageSync("USER")
    var _this = this
    wx.request({
      url: `${BASE_URL}/visa/visadata`,
      method: "POST",
      data: {
        cate: e.currentTarget.dataset.type,
        type: 'xiaochengxv',
        uid: userinfo.id,
      },
      header: {
        'Content-Type': 'application/json' //GET方式是这个
      },
      success(res) {
        console.log(res)
        wx.navigateTo({
          url: `./lvyou_visa/index?price=799&type=${e.currentTarget.dataset.type}`,
        })
      }
    })
  },










  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})